//
//  AppDelegate.m
//  EMMApp
//
//  Created by Mac on 16/4/25.
//  Copyright © 2016年 YiXun. All rights reserved.
//

#import "AppDelegate.h"
#import "EMMNewLoginViewController.h"
#import "EMMTabBarController.h"
#import "UMMobClick/MobClick.h"

#import <AdSupport/AdSupport.h>
#import "YTKNetworkConfig.h"
#import "NoticeViewController.h"
#import "RemindDetailsViewController.h"
#import "RemoteLoginApi.h"
#import "ProjectModel.h"

#import "KnowDetailsViewController.h"
#import "SignDetailsViewController.h"
#import "SubscriptionDetailsViewController.h" 
#import "EMMTouristsViewController.h"
#import "TouristsDetailWebViewController.h"
#import "RemindViewController.h"
#import "FollowUpViewController.h"

#ifdef DEBUG
    FILE *fopen$UNIX2003(const char *filename, const char *mode) {
        return fopen(filename, mode);
    }
    size_t fwrite$UNIX2003(const void *ptr, size_t size, size_t nitems, FILE *stream) {
        return fwrite(ptr, size, nitems, stream);
    }
#endif

@interface AppDelegate ()<UIAlertViewDelegate,JPUSHRegisterDelegate>
{
    NSInteger countBage;
    NSString *status;
    NSString *projectCode;//项目code
    NSString *projectName;//项目名称
    
}
@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    UIViewController *vc = [[UIViewController alloc] init];
    vc.view.backgroundColor = [UIColor blackColor];
    self.window.rootViewController = vc;
    [self.window makeKeyAndVisible];
    
    //友盟监测
//    UMConfigInstance.appKey = @"5861c9549f06fd4f6d002db4";//测试环境
    UMConfigInstance.appKey = @"5861c8459f06fd16a40003ab";//生产环境

    UMConfigInstance.channelId = @"App Store";//渠道标识
    [MobClick startWithConfigure:UMConfigInstance];//配置以上参数后调用此方法初始化SDK！
    [MobClick setCrashReportEnabled:YES];//开启错误收集 默认yes
    [MobClick setLogEnabled:YES];//普通测试流程 (测试数据和用户数据同时处理)
    
    
    [NSThread sleepForTimeInterval:0.1];
//
    NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
    [defaultCenter addObserver:self selector:@selector(networkDidReceiveMessage:) name:kJPFNetworkDidReceiveMessageNotification object:nil];
    
    // 建立通知，分别在建立连接，关闭连接，注册成功，登录成功后调用相关方法
    [defaultCenter addObserver:self selector:@selector(networkDidSetup:) name:kJPFNetworkDidSetupNotification object:nil];
    [defaultCenter addObserver:self selector:@selector(networkDidClose:) name:kJPFNetworkDidCloseNotification object:nil];
    [defaultCenter addObserver:self selector:@selector(networkDidRegister:) name:kJPFNetworkDidRegisterNotification object:nil];
    [defaultCenter addObserver:self selector:@selector(networkDidLogin:) name:kJPFNetworkDidLoginNotification object:nil];
    
   //注册极光
    // 3.0.0及以后版本注册可以这样写，也可以继续用旧的注册方式
    NSString *advertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
    JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
    entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound;
    [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
    [JPUSHService setupWithOption:launchOptions appKey:appKey
                          channel:channel
                 apsForProduction:isProduction
            advertisingIdentifier:advertisingId];
    
    //2.1.9版本新增获取registration id block接口。
    [JPUSHService registrationIDCompletionHandler:^(int resCode, NSString *registrationID) {
        if(resCode == 0){
            NSLog(@"registrationID获取成功：%@",registrationID);
        }
        else{
            NSLog(@"registrationID获取失败，code：%d",resCode);
        }
    }];
//
//    if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
//        //可以添加自定义categories
//        [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
//                                                          UIUserNotificationTypeSound |
//                                                          UIUserNotificationTypeAlert)
//                                              categories:nil];
//    } else {
//        //categories 必须为nil
//        [JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
//                                                          UIRemoteNotificationTypeSound |
//                                                          UIRemoteNotificationTypeAlert)
//                                              categories:nil];
//    }
//    
//    //如不需要使用IDFA，advertisingIdentifier 可为nil
//    [JPUSHService setupWithOption:launchOptions appKey:appKey
//                          channel:channel
//                 apsForProduction:isProduction
//            advertisingIdentifier:advertisingId];
//  
//    [JPUSHService crashLogON];
    //网络请求
    YTKNetworkConfig *config = [YTKNetworkConfig sharedInstance];
    config.baseUrl = apiBaseUrl;
    config.cdnUrl = cdUrl;
    
    //jsomdel
    JSONKeyMapper *keyMapper = [[JSONKeyMapper alloc] initWithDictionary:
                                @{
                                  @"id":@"Id",
                                  @"value":@"Value",
                                  @"newPwd":@"myNewPwd",
                                  @"newVersion":@"myNewVersion",
                                  @"newAddedProductlist":@"myNewAddedProductlist"
                                  }];
    [JSONModel setGlobalKeyMapper:keyMapper];
    
//    [JPUSHService setBadge:0];
    
    // 获取当前应用程序的UIApplication对象
    UIApplication *app = [UIApplication sharedApplication];
    
    // iOS 8 系统要求设置通知的时候必须经过用户许可。
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil];
    
    [app registerUserNotificationSettings:settings];
    
    // 设置应用程序右上角的"通知图标"Badge
    app.applicationIconBadgeNumber = 0;  // 根据逻辑设置
    
    [self show];
    [self creatKeyboardManager];
    return YES;
}

- (void)show {
    NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
    //取出当前登录状态
    NSString *is_login = [defs objectForKey:@"is_login"];
    if ([NSString isStringEmpty2:is_login] == NO) {
        [self showMain];
    } else {
        [self showLogin];
    }
}

- (void)creatKeyboardManager {
    IQKeyboardManager *keyboardManager = [IQKeyboardManager sharedManager]; // 获取类库的单例变量

    keyboardManager.enable = YES; // 控制整个功能是否启用

    keyboardManager.shouldResignOnTouchOutside = YES; // 控制点击背景是否收起键盘

    keyboardManager.shouldToolbarUsesTextFieldTintColor = YES; // 控制键盘上的工具条文字颜色是否用户自定义

    keyboardManager.toolbarManageBehaviour = IQAutoToolbarBySubviews; // 有多个输入框时，可以通过点击Toolbar 上的“前一个”“后一个”按钮来实现移动到不同的输入框

    keyboardManager.enableAutoToolbar = YES; // 控制是否显示键盘上的工具条

    keyboardManager.shouldShowTextFieldPlaceholder = YES; // 是否显示占位文字

    keyboardManager.placeholderFont = [UIFont boldSystemFontOfSize:17]; // 设置占位文字的字体

    keyboardManager.keyboardDistanceFromTextField = 10.0f; // 输入框距离键盘的距离
}

#pragma mark - 设置推送别名
- (void)setAPService:(NSNotification *)notification {
    NSString *userId = [[NSUserDefaults standardUserDefaults] objectForKey:@"USERID"];
    [JPUSHService setAlias:[NSString stringWithFormat:@"MY_%@",userId] callbackSelector:@selector(tagsAliasCallback:tags:alias:) object:self];
}

#pragma mark - 获取极光推送注册设备的ID
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

    [JPUSHService registerDeviceToken:deviceToken];
    NSLog(@"-----%@",deviceToken);
}

#pragma mark - 接收推送的处理//APNs.正在前台或者后台运行
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    [JPUSHService handleRemoteNotification:userInfo];
    [self handlernotification:userInfo];
    // 取得 APNs 标准信息内容
    NSDictionary *aps = [userInfo valueForKey:@"aps"];
    NSString *content = [aps valueForKey:@"alert"]; //推送显示的内容
    NSInteger badge = [[aps valueForKey:@"badge"] integerValue]; //badge数量
    NSString *sound = [aps valueForKey:@"sound"]; //播放的声音
    
    // 取得Extras字段内容
    NSString *customizeField1 = [userInfo valueForKey:@"customizeExtras"]; //服务端中Extras字段，key是自己定义的
    NSLog(@"content =[%@], badge=[%ld], sound=[%@], customize field  =[%@]",content,badge,sound,customizeField1);
    
    [JPUSHService handleRemoteNotification:userInfo];
    
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    
    // 取得 APNs 标准信息内容
    NSDictionary *aps = [userInfo valueForKey:@"aps"];
    NSString *content = [aps valueForKey:@"alert"];                 // 推送显示的内容
    NSInteger badge = [[aps valueForKey:@"badge"] integerValue];    // badge数量
    NSString *sound = [aps valueForKey:@"sound"];                   // 播放的声音
    
    // 取得Extras字段内容
    NSString *customizeField1 = [userInfo valueForKey:@"customizeExtras"];  // 服务端中Extras字段，key是自己定义的
    NSLog(@"\nAppDelegate:\ncontent =[%@], badge=[%ld], sound=[%@], customize field  =[%@]",content,badge,sound,customizeField1);
    
    // Required
    [JPUSHService handleRemoteNotification:userInfo];
    completionHandler(UIBackgroundFetchResultNewData);
}


#pragma mark - 判断点击icon
- (void)applicationDidBecomeActive:(UIApplication *)application {
//    NSString *isEnterGuidePage = [[NSUserDefaults standardUserDefaults] objectForKey:@"IsEnterGuidePage"];
//    if (!isEnterGuidePage) {
//        [self creatGuidePageView];
//    }else {
//        //有推送
//        if (application.applicationIconBadgeNumber != 0) {
//            self.isHaveJPush = YES;
//            [[NSNotificationCenter defaultCenter] postNotificationName:@"isAppGetJPush" object:nil];
//            [application setApplicationIconBadgeNumber:0];
//        }
//    }
    [UIApplication sharedApplication].applicationIconBadgeNumber = 0;

}

#pragma mark - 自定义消息
//
- (void)networkDidReceiveMessage:(NSNotification *)notification {
    
    NSDictionary * userInfo = [notification userInfo];
    NSLog(@"%@", userInfo);
    [self handlernotification:userInfo];
    NSString *content = [userInfo valueForKey:@"content"];
    NSDictionary *extras = [userInfo valueForKey:@"extras"];

    NSString *action = [extras valueForKey:@"action"]; //自定义参数，key是自己定义的
    projectCode = [extras valueForKey:@"projectCode"];
    projectName = [extras valueForKey:@"projectName"];
    NSString *pushType = [extras valueForKey:@"pushType"];
    NSString *remindCategoryId = [extras valueForKey:@"remindCategoryId"];
    NSString *proId = [extras valueForKey:@"proId"];
    NSString *receiverId = [extras valueForKey:@"receiverId"];
    NSString *customerId = [extras valueForKey:@"customerId"];
    NSString *taskId = [extras valueForKey:@"taskId"];
    NSString *businessId = [extras valueForKey:@"businessId"];
    NSString *tempType = [extras valueForKey:@"tempType"];
    NSString *remindCategory = [extras valueForKey:@"remindCategory"];

    NSLog(@"%@",proId);
    NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
    [userdf setObject:action forKey:@"action"];
    
    [userdf setObject:pushType forKey:@"pushType"];
    [userdf setObject:remindCategoryId forKey:@"remindCategoryId"];
    [userdf setObject:receiverId forKey:@"receiverId"];
    [userdf setObject:taskId forKey:@"taskId"];
    [userdf setObject:customerId forKey:@"customerId"];
    [userdf setObject:businessId forKey:@"businessId"];
    //tempType（跳转类型）：1 审核申请； 2 审核结果； 3 报备消息
    [userdf setObject:tempType forKey:@"tempType"];
    [userdf setObject:remindCategory forKey:@"remindCategory"];

    [userdf synchronize];
//    
    NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
    NSString *is_login = [defs objectForKey:@"is_login"];
    if ([NSString isStringEmpty2:is_login] == NO) {
        if ([pushType isEqualToString:@"yddl"]) {
            [self postRemoteLoginApiContent:content];
        }else if ([pushType isEqualToString:@"xmzbg"]) {
            NSDictionary *dataDict = [[extras valueForKey:@"Data"] objectFromJSONString];
            NSString *projectIdS = [dataDict objectForKey:@"projectId"];
            NSString *projectId = [defs objectForKey:@"projectId"];
            if (![projectIdS isEqualToString:projectId]) {
                //projectId项目的id 不等
                [self postGetProjectListApiProjectIdS:projectIdS projectId:projectId];
            }else {
                //projectId项目的id 相等
                [self postGetProjectListApiProjectIdS:projectIdS projectId:projectId];
                
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"消息推送" message:[content stringByReplacingOccurrencesOfString:@"-->"withString:@"-"] delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
                alertView.tag = 1002;
                [alertView show];
            }
        }else if ([pushType isEqualToString:@"NT03"] ||
                  [pushType isEqualToString:@"NT04"] ||
                  [pushType isEqualToString:@"NT05"] ||
                  [pushType isEqualToString:@"NT38"] ||
                  [pushType isEqualToString:@"NT39"] ||
                  [pushType isEqualToString:@"NT40"] ||
                  [pushType isEqualToString:@"NT41"] ||
                  [pushType isEqualToString:@"NT42"] ||
                  [pushType isEqualToString:@"NT43"] ||
                  [pushType isEqualToString:@"NT44"] ||[pushType isEqualToString:@"NT45"] ) {
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"消息推送" message:[content stringByReplacingOccurrencesOfString:@"-->"withString:@"-"] delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
            alertView.tag = 1005;
            [alertView show];
            //客户维护 - NT03、NT04、NT05 不跳转
        }else if ([pushType isEqualToString:@"NT06"]) {
            //待处理客户
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"消息推送" message:[content stringByReplacingOccurrencesOfString:@"-->"withString:@"-"] delegate:self cancelButtonTitle:@"忽略" otherButtonTitles:@"查看", nil];
            alertView.tag = 1006;
            [alertView show];
        }else if ([pushType isEqualToString:@"NT07"]) {
            //07 - 37 审核中 - 认筹
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"消息推送" message:[content stringByReplacingOccurrencesOfString:@"-->"withString:@"-"] delegate:self cancelButtonTitle:@"忽略" otherButtonTitles:@"查看", nil];
            alertView.tag = 1007;
            [alertView show];
        }else if ([pushType isEqualToString:@"NT08"]) {
            //07 - 37 审核中 - 认购
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"消息推送" message:[content stringByReplacingOccurrencesOfString:@"-->"withString:@"-"] delegate:self cancelButtonTitle:@"忽略" otherButtonTitles:@"查看", nil];
            alertView.tag = 1008;
            [alertView show];
        }else if ([pushType isEqualToString:@"NT09"]) {
            //07 - 37 审核中 - 签约
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"消息推送" message:[content stringByReplacingOccurrencesOfString:@"-->"withString:@"-"] delegate:self cancelButtonTitle:@"忽略" otherButtonTitles:@"查看", nil];
            alertView.tag = 1009;
            [alertView show];
        }else if ([pushType isEqualToString:@"NT24"] ||
                  [pushType isEqualToString:@"NT25"] ||
                  [pushType isEqualToString:@"NT20"] ||
                  [pushType isEqualToString:@"NT21"]) {
            //无房认筹、有房认筹
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"消息推送" message:[content stringByReplacingOccurrencesOfString:@"-->"withString:@"-"] delegate:self cancelButtonTitle:@"忽略" otherButtonTitles:@"查看", nil];
            alertView.tag = 1010;
            [alertView show];
        }else if ([pushType isEqualToString:@"NT01"] ||
                  [pushType isEqualToString:@"NT26"] ||
                  [pushType isEqualToString:@"NT22"]) {
            //认购
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"消息推送" message:[content stringByReplacingOccurrencesOfString:@"-->"withString:@"-"] delegate:self cancelButtonTitle:@"忽略" otherButtonTitles:@"查看", nil];
            alertView.tag = 1011;
            [alertView show];
        }else if ([pushType isEqualToString:@"NT02"] ||
                  [pushType isEqualToString:@"NT27"] ||
                  [pushType isEqualToString:@"NT23"]) {
            //人、签约
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"消息推送" message:[content stringByReplacingOccurrencesOfString:@"-->"withString:@"-"] delegate:self cancelButtonTitle:@"忽略" otherButtonTitles:@"查看", nil];
            alertView.tag = 1012;
            [alertView show];
        }else if ([pushType isEqualToString:@"NT14"] ||
                  [pushType isEqualToString:@"NT32"]  ) {
            //-申请退认筹、NT32审核结果认筹
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"消息推送" message:[content stringByReplacingOccurrencesOfString:@"-->"withString:@"-"] delegate:self cancelButtonTitle:@"忽略" otherButtonTitles:@"查看", nil];
            alertView.tag = 1013;
            [alertView show];
        }else if ([pushType isEqualToString:@"NT13"] ||
                  [pushType isEqualToString:@"NT31"]  ) {
            //NT13-申请退认购、NT31审核结果认购
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"消息推送" message:[content stringByReplacingOccurrencesOfString:@"-->"withString:@"-"] delegate:self cancelButtonTitle:@"忽略" otherButtonTitles:@"查看", nil];
            alertView.tag = 1014;
            [alertView show];
        }else if ([pushType isEqualToString:@"NT12"] ||
                  [pushType isEqualToString:@"NT30"] ||
                  [pushType isEqualToString:@"NT16"] ||
                  [pushType isEqualToString:@"NT34"] ||
                  [pushType isEqualToString:@"NT17"] ||
                  [pushType isEqualToString:@"NT35"]   ) {
            //NT12-申请退签约、NT30审核结果签约 NT16-延期签约申请 NT34-延期签约结果 NT17-应收延期款申请、NT34-应收延期款结果
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"消息推送" message:[content stringByReplacingOccurrencesOfString:@"-->"withString:@"-"] delegate:self cancelButtonTitle:@"忽略" otherButtonTitles:@"查看", nil];
            alertView.tag = 1015;
            [alertView show];
        }else if ([pushType isEqualToString:@"NT18"] ||
                  [pushType isEqualToString:@"NT19"] ||
                  [pushType isEqualToString:@"NT36"] ||
                  [pushType isEqualToString:@"NT37"] ||
                  [pushType isEqualToString:@"NT10"] ||
                  [pushType isEqualToString:@"NT101"]||
                  [pushType isEqualToString:@"NT28"] ||
                  [pushType isEqualToString:@"NT281"] ) {
            //NT18-价格方案、NT19面积补差、NT36价格方案结果、NT37-面积补差结果 NT10-认购折扣审批审核列表、NT101-签约折扣申请列表
            //NT28-认购折扣结果列表、NT281-签约折扣审批结果列表
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"消息推送" message:[content stringByReplacingOccurrencesOfString:@"-->"withString:@"-"] delegate:self cancelButtonTitle:@"忽略" otherButtonTitles:@"查看", nil];
            alertView.tag = 1016;
            
            [alertView show];
        }else if ([pushType isEqualToString:@"NT11"] ||
                  [pushType isEqualToString:@"NT29"]  ) {
            //NT11-认购换房申请、NT29认购换房申请结果、
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"消息推送" message:[content stringByReplacingOccurrencesOfString:@"-->"withString:@"-"] delegate:self cancelButtonTitle:@"忽略" otherButtonTitles:@"查看", nil];
            alertView.tag = 1017;
            [alertView show];
        }else if ([pushType isEqualToString:@"NT111"] ||
                  [pushType isEqualToString:@"NT291"]  ) {
            //NT11-认购签约换房审批申请、NT29签约换房审批申申请结果、
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"消息推送" message:[content stringByReplacingOccurrencesOfString:@"-->"withString:@"-"] delegate:self cancelButtonTitle:@"忽略" otherButtonTitles:@"查看", nil];
            alertView.tag = 1018;
            [alertView show];
        }else if ([pushType isEqualToString:@"NT15"] ||
                  [pushType isEqualToString:@"NT30"]  ) {
            //NT11-认购更名申请、NT29认购换更名结果、
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"消息推送" message:[content stringByReplacingOccurrencesOfString:@"-->"withString:@"-"] delegate:self cancelButtonTitle:@"忽略" otherButtonTitles:@"查看", nil];
            alertView.tag = 1019;
            [alertView show];
        }else if ([pushType isEqualToString:@"NT151"] ||
                  [pushType isEqualToString:@"NT301"]  ) {
            //NT151-签约更名申请、NT301签约更名结果、
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"消息推送" message:[content stringByReplacingOccurrencesOfString:@"-->"withString:@"-"] delegate:self cancelButtonTitle:@"忽略" otherButtonTitles:@"查看", nil];
            alertView.tag = 1020;
            [alertView show];
        }else if ([pushType isEqualToString:@"NC"] ) {
            //公告
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"消息推送" message:[content stringByReplacingOccurrencesOfString:@"-->"withString:@"-"] delegate:self cancelButtonTitle:@"忽略" otherButtonTitles:@"查看", nil];
            alertView.tag = 1001;
            [alertView show];
        }else {
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"消息推送" message:[content stringByReplacingOccurrencesOfString:@"-->"withString:@"-"] delegate:self cancelButtonTitle:@"忽略" otherButtonTitles:@"查看", nil];
            alertView.tag = 1021;
            [alertView show];
        }
    }
}


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
    NSString *pushType = [userdf objectForKey:@"pushType"];
    NSString *businessId = [userdf objectForKey:@"businessId"];
    NSString *taskId = [userdf objectForKey:@"taskId"];
    NSString *customerId = [userdf objectForKey:@"customerId"];
    NSString *tempType = [userdf objectForKey:@"tempType"];
    NSString *remindCategoryId = [userdf objectForKey:@"remindCategoryId"];
    NSString *remindCategory = [userdf objectForKey:@"remindCategory"];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"isBackPushNotification" object:nil];

    if (alertView.tag == 1001) {
        if (buttonIndex == 0) {
           
        }else if (buttonIndex == 1) {
            NSLog(@"2");
            NoticeViewController *evc = [[NoticeViewController alloc] init];
            evc.hidesBottomBarWhenPushed = YES;
            evc.isNot = NO;
            evc.projectCode = projectCode;
            evc.projectName = projectName;
            UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:evc];
            [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
            }];
        }
    }
    else if (alertView.tag == 1002) {
        [self show];
 
    }
    else if (alertView.tag == 1003) {
        if ([pushType isEqualToString:@"yddl"]){
            if ([status isEqualToString:@"2"]) {
                NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
                NSDictionary *dictionary = [defs dictionaryRepresentation];
                for(NSString *key in [dictionary allKeys]){
                    if ([key isEqualToString:@"DeviceToken123"] ||
                        [key isEqualToString:@"loginText"] ||
                        [key isEqualToString:@"provinceCityDistrict"]) {
                        
                    }else {
                        [defs removeObjectForKey:key];
                        [defs synchronize];
                    }
                }
                [appInstance showLogin];
            }
        }
    }
    else if (alertView.tag == 1006) {
        if (buttonIndex == 0) {
            
        }else if (buttonIndex == 1) {
            //客户详情
            TouristsDetailWebViewController *tvc = [[TouristsDetailWebViewController alloc] init];
            tvc.hidesBottomBarWhenPushed = YES;
            tvc.customerId = customerId;
            tvc.isNot = YES;
            UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:tvc];
            [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
            }];
        }
    }
    else if (alertView.tag == 1007){
        if (buttonIndex == 0) {
            
        }else if (buttonIndex == 1) {
            KnowDetailsViewController *kon = [[KnowDetailsViewController alloc] init];
            kon.businessId = businessId;
            kon.taskId = taskId;
            kon.customerId = customerId;
            kon.isAudit = @"1";
            kon.isNot = NO;
            UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:kon];
            [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
            }];
        }
    }
    else if (alertView.tag == 1008){
        if (buttonIndex == 0) {
            
        }else if (buttonIndex == 1) {
            SubscriptionDetailsViewController *sub = [[SubscriptionDetailsViewController alloc] init];
            sub.businessId = businessId;
            sub.taskId = taskId;
            sub.customerId = customerId;
            sub.isAudit = @"1";
            sub.isNot = NO;
            UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:sub];
            [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
            }];
        }
       
    }
    else if (alertView.tag == 1009){
        if (buttonIndex == 0) {
            
        }else if (buttonIndex == 1) {
            SignDetailsViewController *signVC = [[SignDetailsViewController alloc] init];
            signVC.businessId = businessId;
            signVC.taskId = taskId;
            signVC.customerId = customerId;
            signVC.isAudit = @"1";
            signVC.isNot = NO;
            UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:signVC];
            [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
            }];
        }
        
    }
    else if (alertView.tag == 1010){
        if (buttonIndex == 0) {
            
        }else if (buttonIndex == 1) {
            KnowDetailsViewController *kon = [[KnowDetailsViewController alloc] init];
            kon.payDepositId = businessId;
            kon.taskId = taskId;
            kon.customerId = customerId;
            kon.isNot = NO;
            UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:kon];
            [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
            }];
        }
      
    }
    else if (alertView.tag == 1011){
        if (buttonIndex == 0) {
            
        }else if (buttonIndex == 1) {
            SubscriptionDetailsViewController *sub = [[SubscriptionDetailsViewController alloc] init];
            sub.subscribeId = businessId;
            sub.taskId = taskId;
            sub.customerId = customerId;
            sub.isNot = NO;
            UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:sub];
            [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
            }];
        }
        
    }
    else if (alertView.tag == 1012){
        if (buttonIndex == 0) {
            
        }else if (buttonIndex == 1) {
            SignDetailsViewController *signVC = [[SignDetailsViewController alloc] init];
            signVC.signedId = businessId;
            signVC.taskId = taskId;
            signVC.customerId = customerId;
            signVC.isNot = NO;
            UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:signVC];
            [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
            }];
        }
    }
    else if (alertView.tag == 1013){
        if (buttonIndex == 0) {
            
        }else if (buttonIndex == 1) {
            if ([tempType isEqualToString:@"1"] || [tempType isEqualToString:@"2"]) {
                //1.审核详情列表界面
                //2.审核结果列表界面
                RemindDetailsViewController *rvc = [[RemindDetailsViewController alloc] init];
                rvc.remindCategoryId = remindCategoryId;
                rvc.nameTitleString = remindCategory;
                rvc.isNot = NO;
                rvc.projectCode = projectCode;
                UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:rvc];
                [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
                }];
            }else if ([tempType isEqualToString:@"3"]) {//报备消息类型
                KnowDetailsViewController *kon = [[KnowDetailsViewController alloc] init];
                kon.payDepositId = businessId;
                kon.taskId = taskId;
                kon.customerId = customerId;
                kon.isNot = NO;
                UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:kon];
                [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
                }];
            }else {
                RemindViewController *evc = [[RemindViewController alloc] init];
                UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:evc];
                [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
                }];
            }
        }
    }
    else if (alertView.tag == 1014){
        if (buttonIndex == 0) {
            
        }else if (buttonIndex == 1) {
            if ([tempType isEqualToString:@"1"] || [tempType isEqualToString:@"2"]) {
                //1.审核详情列表界面
                //2.审核结果列表界面
                RemindDetailsViewController *rvc = [[RemindDetailsViewController alloc] init];
                rvc.remindCategoryId = remindCategoryId;
                rvc.nameTitleString = remindCategory;
                rvc.isNot = NO;
                rvc.projectCode = projectCode;
                UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:rvc];
                [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
                }];
            }else if ([tempType isEqualToString:@"3"]) {//报备消息类型
                SubscriptionDetailsViewController *sub = [[SubscriptionDetailsViewController alloc] init];
                sub.subscribeId = businessId;
                sub.taskId = taskId;
                sub.customerId = customerId;
                sub.isNot = NO;
                UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:sub];
                [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
                }];
            }else {
                RemindViewController *evc = [[RemindViewController alloc] init];
                UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:evc];
                [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
                }];
            }
        }
    }
    else if (alertView.tag == 1015){
        if (buttonIndex == 0) {
            
        }else if (buttonIndex == 1) {
            if ([tempType isEqualToString:@"1"] || [tempType isEqualToString:@"2"]) {
                //1.审核详情列表界面
                //2.审核结果列表界面
                RemindDetailsViewController *rvc = [[RemindDetailsViewController alloc] init];
                rvc.remindCategoryId = remindCategoryId;
                rvc.nameTitleString = remindCategory;
                rvc.isNot = NO;
                rvc.projectCode = projectCode;
                UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:rvc];
                [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
                }];
            }else if ([tempType isEqualToString:@"3"]) {//报备消息类型
                SignDetailsViewController *signVC = [[SignDetailsViewController alloc] init];
                signVC.signedId = businessId;
                signVC.taskId = taskId;
                signVC.customerId = customerId;
                signVC.isNot = NO;
                UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:signVC];
                [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
                }];
            }else {
                RemindViewController *evc = [[RemindViewController alloc] init];
                UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:evc];
                [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
                }];
            }
        }
    }
    else if (alertView.tag == 1016){
        if (buttonIndex == 0) {
            
        }else if (buttonIndex == 1) {
            //1.审核详情列表界面
            //2.审核结果列表界面
            RemindDetailsViewController *rvc = [[RemindDetailsViewController alloc] init];
            rvc.remindCategoryId = remindCategoryId;
            rvc.nameTitleString = remindCategory;
            rvc.isNot = NO;
            rvc.projectCode = projectCode;
            UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:rvc];
            [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
            }];
        }
    }
    else if (alertView.tag == 1017){
        if (buttonIndex == 0) {
            
        }else if (buttonIndex == 1) {
            //1.审核详情列表界面
            //2.审核结果列表界面
            
            if ([tempType isEqualToString:@"1"]) {
                RemindDetailsViewController *rvc = [[RemindDetailsViewController alloc] init];
                rvc.remindCategoryId = remindCategoryId;
                rvc.nameTitleString = remindCategory;
                rvc.isNot = NO;
                rvc.projectCode = projectCode;
                UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:rvc];
                [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
                }];
            }else if ([tempType isEqualToString:@"2"] || [tempType isEqualToString:@"3"]) {
                SubscriptionDetailsViewController *sub = [[SubscriptionDetailsViewController alloc] init];
                sub.subscribeId = businessId;
                sub.taskId = taskId;
                sub.customerId = customerId;
                sub.isNot = NO;
                UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:sub];
                [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
                }];
            }else {
                RemindViewController *evc = [[RemindViewController alloc] init];
                UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:evc];
                [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
                }];
            }
        }
    }
    else if (alertView.tag == 1018){
        if (buttonIndex == 0) {
            
        }else if (buttonIndex == 1) {
            //1.审核详情列表界面
            //2.审核结果列表界面
            if ([tempType isEqualToString:@"1"]) {
                RemindDetailsViewController *rvc = [[RemindDetailsViewController alloc] init];
                rvc.remindCategoryId = remindCategoryId;
                rvc.nameTitleString = remindCategory;
                rvc.isNot = NO;
                rvc.projectCode = projectCode;
                UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:rvc];
                [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
                }];
            }else if ([tempType isEqualToString:@"2"] || [tempType isEqualToString:@"3"]) {
                
                SignDetailsViewController *signVC = [[SignDetailsViewController alloc] init];
                signVC.signedId = businessId;
                signVC.taskId = taskId;
                signVC.customerId = customerId;
                signVC.isNot = NO;
                UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:signVC];
                [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
                }];
            }else {
                RemindViewController *evc = [[RemindViewController alloc] init];
                UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:evc];
                [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
                }];
            }
        }
    }
    else if (alertView.tag == 1019){
        if (buttonIndex == 0) {
            
        }else if (buttonIndex == 1) {
            //1.审核详情列表界面
            //2.审核结果列表界面
            
            if ([tempType isEqualToString:@"1"] || [tempType isEqualToString:@"2"]) {
                RemindDetailsViewController *rvc = [[RemindDetailsViewController alloc] init];
                rvc.remindCategoryId = remindCategoryId;
                rvc.nameTitleString = remindCategory;
                rvc.isNot = NO;
                rvc.projectCode = projectCode;
                UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:rvc];
                [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
                }];
            }else if ([tempType isEqualToString:@"3"]) {
                SubscriptionDetailsViewController *sub = [[SubscriptionDetailsViewController alloc] init];
                sub.subscribeId = businessId;
                sub.taskId = taskId;
                sub.customerId = customerId;
                sub.isNot = NO;
                UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:sub];
                [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
                }];
            }else {
                RemindViewController *evc = [[RemindViewController alloc] init];
                UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:evc];
                [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
                }];
            }
        }
    }
    else if (alertView.tag == 1020){
        if (buttonIndex == 0) {
            
        }else if (buttonIndex == 1) {
            //1.审核详情列表界面
            //2.审核结果列表界面
            if ([tempType isEqualToString:@"1"] || [tempType isEqualToString:@"2"] ) {
                RemindDetailsViewController *rvc = [[RemindDetailsViewController alloc] init];
                rvc.remindCategoryId = remindCategoryId;
                rvc.nameTitleString = remindCategory;
                rvc.isNot = NO;
                rvc.projectCode = projectCode;
                UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:rvc];
                [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
                }];
            }else if ([tempType isEqualToString:@"3"]) {
                SignDetailsViewController *signVC = [[SignDetailsViewController alloc] init];
                signVC.signedId = businessId;
                signVC.taskId = taskId;
                signVC.customerId = customerId;
                signVC.isNot = NO;
                UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:signVC];
                [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
                }];
               
            }else {
                RemindViewController *evc = [[RemindViewController alloc] init];
                UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:evc];
                [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
                }];
            }
        }
    }
    else if (alertView.tag == 1021) {
        if (buttonIndex == 0) {
            
        }else if (buttonIndex == 1) {
            //1审核申请、2审核结果、3报备消息、4逾期未签约、5逾期未付款、6待处理客户、7下次跟进提醒
            
            if ([tempType isEqualToString:@"1"] || [tempType isEqualToString:@"2"]) {
                RemindDetailsViewController *rvc = [[RemindDetailsViewController alloc] init];
                rvc.remindCategoryId = remindCategoryId;
                rvc.nameTitleString = remindCategory;
                rvc.isNot = NO;
                rvc.projectCode = projectCode;
                UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:rvc];
                [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
                }];
            }else if ([tempType isEqualToString:@"3"]) {
                RemindViewController *evc = [[RemindViewController alloc] init];
                UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:evc];
                [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
                }];
            }else if ([tempType isEqualToString:@"4"]) {
                SubscriptionDetailsViewController *sub = [[SubscriptionDetailsViewController alloc] init];
                sub.businessId = businessId;
                sub.taskId = taskId;
                sub.customerId = customerId;
                sub.isAudit = @"1";
                sub.isNot = NO;
                UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:sub];
                [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
                }];
            }else if ([tempType isEqualToString:@"5"]) {
                SignDetailsViewController *signVC = [[SignDetailsViewController alloc] init];
                signVC.businessId = businessId;
                signVC.taskId = taskId;
                signVC.customerId = customerId;
                signVC.isAudit = @"1";
                signVC.isNot = NO;
                UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:signVC];
                [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
                }];
            }else if ([tempType isEqualToString:@"6"]) {
                //客户详情
                TouristsDetailWebViewController *tvc = [[TouristsDetailWebViewController alloc] init];
                tvc.hidesBottomBarWhenPushed = YES;
                tvc.customerId = customerId;
                tvc.isNot = YES;
                UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:tvc];
                [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
                }];
            }else if ([tempType isEqualToString:@"7"]) {
                NSArray *arr = [remindCategory componentsSeparatedByString:@","];
                if (arr.count == 8) {
                    FollowUpViewController *fvc = [[FollowUpViewController alloc] init];
                    //    fvc.hidesBottomBarWhenPushed = YES;
                    fvc.customerId = customerId;
                    fvc.followId = arr[0];
                    fvc.stringNum = @"1";
                    UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:fvc];
                    [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
                    }];
                }else {
                    
                }
            }else {
                RemindViewController *evc = [[RemindViewController alloc] init];
                UINavigationController *navroot = [[UINavigationController alloc] initWithRootViewController:evc];
                [self.window.rootViewController presentViewController:navroot animated:YES completion:^{
                }];
            }
        }
    }
}


- (void)postRemoteLoginApiContent:(NSString *)content {
    RemoteLoginApi *api = [[RemoteLoginApi alloc] initWith];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        RemoteLoginApi *result = (RemoteLoginApi *)request;
        if (result.isSuccess) {
            RemoteLogin *get = result.resultData;
            status = get.status;
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"消息推送" message:[content stringByReplacingOccurrencesOfString:@"-->"withString:@"-"] delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
            alertView.tag = 1003;
            [alertView show];
        } else {
            if ([result.resultData.errorCode isEqualToString:@"YUplf0wyU5vPVssLSG"] || [result.resultData.errorCode isEqualToString:@"108E65843mYuwqb01X"]) {
                NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
                NSDictionary *dictionary = [defs dictionaryRepresentation];
                for(NSString *key in [dictionary allKeys]){
                    if ([key isEqualToString:@"DeviceToken123"] ||
                        [key isEqualToString:@"loginText"] ||
                        [key isEqualToString:@"provinceCityDistrict"]) {
                    }else {
                        [defs removeObjectForKey:key];
                        [defs synchronize];
                    }
                }
                
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:result.resultData.errorMsg delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
                alertView.tag = 1003;
                [alertView show];
            }
        }
    } failure:^(YTKBaseRequest *request) {
        
    }];
}

//获取项目列表
- (void)postGetProjectListApiProjectIdS:(NSString *)projectIdS projectId:(NSString *)projectidString {
    GetProjectListApi *api = [[GetProjectListApi alloc] initWith];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        GetProjectListApi *result = (GetProjectListApi *)request;
        if (result.isSuccess) {
            GetProjectList *get = result.resultData;
            if (get.projectList.count > 0) {
                NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
                NSMutableArray *arr = [[NSMutableArray alloc] init];
                NSMutableArray *projectArray = [[NSMutableArray alloc] init];
                for (ProjectList *list in get.projectList) {
                    [arr addObject:list];
                    ProjectModel *model = [[ProjectModel alloc] init];
                    model.projectCode = list.projectCode;
                    model.projectName = list.projectName;
                    model.projectId = list.projectId;
                    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:model];
                    [projectArray addObject:data];
                }
                [userdf setObject:projectArray forKey:@"projectArray"];
                if ([projectIdS isEqualToString:projectidString]) {
                    ProjectList *lsit1 = [arr objectAtIndex:0];
                    [userdf setObject:lsit1.projectCode forKey:@"projectCode"];
                    [userdf setObject:lsit1.projectId forKey:@"projectId"];
                    [userdf setObject:lsit1.projectName forKey:@"projectName"];
                    [userdf setObject:@"0" forKey:@"indexString"];
                    [userdf synchronize];
                }
            }
        } else {
            if ([result.resultData.errorCode isEqualToString:@"YUplf0wyU5vPVssLSG"] || [result.resultData.errorCode isEqualToString:@"108E65843mYuwqb01X"]) {
                NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
                NSDictionary *dictionary = [defs dictionaryRepresentation];
                for(NSString *key in [dictionary allKeys]){
                    if ([key isEqualToString:@"DeviceToken123"] ||
                        [key isEqualToString:@"loginText"] ||
                        [key isEqualToString:@"provinceCityDistrict"]) {
                    }else {
                        [defs removeObjectForKey:key];
                        [defs synchronize];
                    }
                }
                
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:result.resultData.errorMsg delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
                alertView.tag = 1003;
                [alertView show];
            }
        }
    } failure:^(YTKBaseRequest *request) {
    }];
}


- (void)tagsAliasCallback:(int)iResCode tags:(NSSet*)tags alias:(NSString*)alias
{
    if (countBage>=9) {
        return;
    }
    
    //这里的iResCode返回0才证明设置成功
    NSLog(@"rescode: %d, \ntags: %@, \nalias: %@\n", iResCode, tags , alias);
    if (iResCode == 0) {
        [IDTools setValueStr:[JPUSHService registrationID] keyStr:@"DeviceToken123"];
        NSLog(@"------->>>> registrationID success %@", [JPUSHService registrationID]);
    } else {
        NSLog(@"------->>>>> registrationID failed %@", [JPUSHService registrationID]);
        
//        [JPUSHService setTags:[NSSet setWithObjects:@"tag1",nil] alias:@"myiphone5" callbackSelector:@selector(tagsAliasCallback:tags:alias:) target:self];
        
        [JPUSHService setTags:[NSSet setWithObjects:@"tag1",nil] alias:@"myiphone5" callbackSelector:@selector(tagsAliasCallback:tags:alias:) object:self];
        countBage++;
        
        NSLog(@"countBage%ld", (long)countBage);
    }
}

- (void)networkDidSetup:(NSNotification *)notification
{
    NSLog(@"------->>>>>已连接");
}

- (void)networkDidClose:(NSNotification *)notification
{
    NSLog(@"------->>>>>未连接。。。");
}

- (void)networkDidRegister:(NSNotification *)notification
{
    NSLog(@"------->>>>>已注册");
}

- (void)networkDidLogin:(NSNotification *)notification
{
    NSLog(@"------->>>>>已登录");
    
    if ([JPUSHService registrationID]) {
        NSLog(@"get RegistrationID:%@",[JPUSHService registrationID]); //获取registrationID
        [IDTools setValueStr:[JPUSHService registrationID] keyStr:@"DeviceToken123"];
    }
}

#pragma mark - 极光推送通知

- (void)handlernotification:(NSDictionary *)userInfo
{
    NSLog(@"\napns -> Receive Data:\n%@", userInfo);
    
}

- (void)customizeInterface {
    [self setUpNavigationBarAppearance];
}
/**
 *  设置navigationBar样式
 */
- (void)setUpNavigationBarAppearance {
    UINavigationBar *navigationBarAppearance = [UINavigationBar appearance];
    
    UIImage *backgroundImage = nil;
    NSDictionary *textAttributes = nil;
    if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) {
        backgroundImage = [UIImage imageNamed:@"navigationbar_background_tall"];
        
        textAttributes = @{
                           NSFontAttributeName: [UIFont boldSystemFontOfSize:20],
                           NSForegroundColorAttributeName: [UIColor blackColor],
                           };
    } else {
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0
        backgroundImage = [UIImage imageNamed:@"navigationbar_background"];
        
        textAttributes = @{
                           UITextAttributeFont: [UIFont boldSystemFontOfSize:20],
                           UITextAttributeTextColor: [UIColor blackColor],
                           UITextAttributeTextShadowColor: [UIColor clearColor],
                           UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetZero],
                           };
#endif
    }
    
    [navigationBarAppearance setBackgroundImage:backgroundImage
                                  forBarMetrics:UIBarMetricsDefault];
    [navigationBarAppearance setTitleTextAttributes:textAttributes];
}

- (void)showLogin {
    EMMNewLoginViewController *vc = [[EMMNewLoginViewController alloc] init];
    [self.window setRootViewController:vc];
    [self.window makeKeyAndVisible];
}

- (void)showMain {
    EMMTabBarController *tabBarControllerConfig = [[EMMTabBarController alloc] init];
    [self.window setRootViewController:tabBarControllerConfig.tabBarController];
    [self.window makeKeyAndVisible];
    //设置navigation样式
    [self customizeInterface];
}

#pragma makrn -
+ (AppDelegate *)shareInstance
{
    return (AppDelegate *)[UIApplication sharedApplication].delegate;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}



@end
